import { IUserInfo, IPage, IPlayRecord } from '~/types/api';

/**
*@param phone 手机号码 
*@param code 验证码 
*@desc 注册接口
*/
export const register = async (opinions: { code: string, phone: string }) => {
    return await useApi<null>('/api/user/v1/send_code', {
        method: 'post',
        body: {
            phone: opinions.phone,
            code: opinions.code
        }
    })
}

/**
*@param phone 手机号码 
*@param password 密码 
*@param code 验证码 
*@desc 登錄接口
*/
export const login = async (opinions: { phone: string, password?: string, code?: string }) => {
    return await useApi<string>('/user/v1/login', {
        method: 'post',
        body: {
            ...opinions
        }
    })
}
/**
 * 修改密码接口
 * @param options code:验证码 phone:手机号 password:密码
 */
export const forget = async (options: {
    phone: string;
    code: string;
    password: string;
}) => {
    return await useApi<null>('/user/v1/forget', {
        method: 'post',
        body: options,
    });
};

/**
 * 获取用户信息
 */
export const getUserInfo = async function () {
    return await useApi<IUserInfo>('/user/v1/detail');
  };

/**
 * 获取最近播放记录
 * @param options code:验证码 phone:手机号 password:密码
 */
export const getPlayRrecord = async (params: {
    page:number;
    size:number
}) => {
    return await useApi<null>('/user/v1/play_record', {
        method: 'post',
        body: params,
    });
};

/**
 * 上报学习时长
 * @param 
 */
export const add = async (params: {
    productId:number;
    episodeId:number;
    duration:number;
}) => {
    return await useApi<null>('/user/v1/duration_record', {
        method: 'post',
        body: params,
    });
};